{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fb31d272",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入opencv 和系统库\n",
    "import cv2 as cv\n",
    "import sys\n",
    "\n",
    "# 读取图像[相对路径]\n",
    "img = cv.imread(\"data/321.jpeg\")\n",
    "if img is None:\n",
    "    sys.exit(\"Could not read the image.\")\n",
    "\n",
    "# 显示图像在名字为Display window 窗口\n",
    "cv.imshow(\"Display window\", img)\n",
    "\n",
    "# 当前程序等待，界面等任意按钮按下，程序释放等待，继续往下执行\n",
    "k = cv.waitKey(0)\n",
    "\n",
    "# 判断是否为按键s。若为s，则保存图像，名字为save.jpeg\n",
    "if k == ord(\"s\"):\n",
    "    cv.imwrite(\"data/save.jpeg\", img)\n",
    "\n",
    "# 释放创建的所有窗口\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8aaa5dba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b6983a6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
